﻿using Newtonsoft.Json;

namespace HttpClientLite.Extensions;

/// <summary>
/// 对象json帮助工具
/// </summary>
internal static class ObjectJsonHelper
{
    /// <summary>
    /// 反序列化
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="json"></param>
    /// <returns></returns>
    internal static T Deserialize<T>(string json) where T : class
        => JsonConvert.DeserializeObject<T>(json, JsonSettings.SerializerSettings)!;

    /// <summary>
    /// 序列化
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="self"></param>
    /// <returns></returns>
    internal static string Serialize<T>(T self) where T : class
        => JsonConvert.SerializeObject(self, JsonSettings.SerializerSettings);
}